import { Request } from 'express';
import { formateDate } from './date.utils';
/**
   * 生成范围随机数
   * @Min 最小值
   * @Max 最大值
   */
export function GetRandomNum(Min, Max): Number {
  var Range = Max - Min;
  var Rand = Math.random();
  return (Min + Math.round(Rand * Range));
}

/**
 * 获取当前用户信息
 * @param request 
 * @returns 
 */
export function GetCurrentUser(request: Request): any {
  return JSON.parse(request.headers.currentUser.toString());
}

/**
 * 生成订单号
 */
var number = 100000
export function generateCode(prefix: string) {
  let dateStr = formateDate(new Date(), "yyyyMMddhhmmss")
  number += number + 1
  let code = prefix + dateStr + number.toString()
  return code
}